//
//  MBProgressHUD+Ext.m
//  HUDREXT
//
//  Created by 红嘴欧 on 2018/6/28.
//  Copyright © 2018年 person.qing. All rights reserved.
//

#import "MBProgressHUD+Ext.h"

@implementation MBProgressHUD (Ext)

+ (void)showTip:(NSString *)tip {
    MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:[MBProgressHUD currentController].view animated:YES];
    HUD.mode = MBProgressHUDModeText;
    HUD.label.text = tip;
    HUD.label.textColor = [UIColor whiteColor];
    HUD.bezelView.backgroundColor = [UIColor blackColor];
    [HUD hideAnimated:YES afterDelay:1];
}

+ (void)showSuccess:(NSString *)success {
    [MBProgressHUD showMessage:success image:@"hud_succeed"];
}

+ (void)showError:(NSString *)error {
    [MBProgressHUD showMessage:error image:@"hud_error"];
}

+ (void)showMessage:(NSString *)message image:(NSString *)name {
    MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:[MBProgressHUD currentController].view animated:YES];
    HUD.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:name]];
    HUD.mode = MBProgressHUDModeCustomView;
    HUD.label.text = message;
    HUD.label.textColor = [UIColor whiteColor];
    HUD.bezelView.backgroundColor = [UIColor blackColor];
    [HUD hideAnimated:YES afterDelay:1];
}

+ (void)show {
    MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:[MBProgressHUD currentController].view animated:YES];
    HUD.mode = MBProgressHUDModeIndeterminate;
    HUD.contentColor = [UIColor whiteColor];
    HUD.backgroundView.style = MBProgressHUDBackgroundStyleBlur;
    HUD.bezelView.backgroundColor = [UIColor blackColor];
    [HUD hideAnimated:YES afterDelay:10];
}

+ (void)hiden {
    [MBProgressHUD hideHUDForView:[MBProgressHUD currentController].view animated:YES];
}

+ (UIViewController *)currentController {
    UIWindow *keyWindow  = [UIApplication sharedApplication].keyWindow;
    UIViewController *vc = keyWindow.rootViewController;
    while (vc.presentedViewController) {
        vc = vc.presentedViewController;
        if ([vc isKindOfClass:[UINavigationController class]]) {
            vc = [(UINavigationController *)vc visibleViewController];
        }
        else if ([vc isKindOfClass:[UITabBarController class]]) {
            vc = [(UITabBarController *)vc selectedViewController];
        }
    }
    return vc;
}

@end
